﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace SPForumWP.ForumTree
{
    public partial class ForumTreeUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MessageBoard.Language currentLanguage = MessageBoard.Language.Get("EN");

            String pageName = "Home.aspx";

            // GroupList
            if (Request.QueryString["Forum"] == null || Request.QueryString["Forum"] == "GroupList")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.URLMessageBoard = pageName;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            // AddGroup
            if (Request.QueryString["Forum"] == "AddGroup")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.URLMessageBoard = pageName;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            //EditGroup
            if (Request.QueryString["Forum"] == "EditGroup")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.URLMessageBoard = pageName;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            ////DeleteGroup
            //If Request.QueryString("Forum") = "DeleteGroup" Then
            //    Dim tree As MessageBoardControl.Tree = New MessageBoardControl.Tree
            //    tree.ImagesFolder = "Images/Forum"
            //    tree.URLMessageBoard = pageName
            //    tree.Language = currentLanguage
            //    treeDiv.Controls.Add(tree)
            //End If

            //CategoryList
            if (Request.QueryString["Forum"] == "CategoryList")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.Group = MessageBoard.Group.Get(int.Parse(Request.QueryString["GroupId"]));
                tree.URLMessageBoard = pageName + "?GroupId=" + tree.Group.Id;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            //AddCategory
            if (Request.QueryString["Forum"] == "AddCategory")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.URLMessageBoard = pageName;
                tree.Group = MessageBoard.Group.Get(int.Parse(Request.QueryString["GroupId"]));
                tree.URLGroup = pageName + "?GroupId=" + tree.Group.Id;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            //// EditCategory
            //If Request.QueryString("Forum") = "EditCategory" Then
            //    Dim tree As MessageBoardControl.Tree = New MessageBoardControl.Tree
            //    tree.ImagesFolder = "Images/Forum"
            //    tree.URLMessageBoard = pageName
            //    tree.Group = MessageBoard.Category.Get(CInt(Request.QueryString("CategoryId"))).Group
            //    tree.URLGroup = pageName + "?GroupId=" & tree.Group.Id
            //    tree.Language = currentLanguage
            //    treeDiv.Controls.Add(tree)
            //End If

            //// Delete Category
            //If Request.QueryString("Forum") = "DeleteCategory" Then
            //    Dim tree As MessageBoardControl.Tree = New MessageBoardControl.Tree
            //    tree.ImagesFolder = "Images/Forum"
            //    tree.URLMessageBoard = pageName
            //    tree.Group = MessageBoard.Category.Get(CInt(Request.QueryString("CategoryId"))).Group
            //    tree.URLGroup = pageName + "?GroupId=" & tree.Group.Id
            //    tree.Language = currentLanguage
            //    treeDiv.Controls.Add(tree)
            //End If

            // AddForum
            if (Request.QueryString["Forum"] == "AddForum")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.Category = MessageBoard.Category.Get(int.Parse(Request.QueryString["CategoryId"]));
                tree.URLMessageBoard = pageName;
                tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Category.Group.Id;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            // EditForum
            if (Request.QueryString["Forum"] == "EditForum")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.Category = MessageBoard.Forum.Get(int.Parse(Request.QueryString["ForumId"])).Category;
                tree.URLMessageBoard = pageName;
                tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Category.Group.Id;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            //// DeleteForum
            //If Request.QueryString("Forum") = "DeleteForum" Then
            //    Dim tree As MessageBoardControl.Tree = New MessageBoardControl.Tree
            //    tree.ImagesFolder = "Images/Forum"
            //    tree.Group = deleteForum.Forum.Category.Group
            //    tree.URLMessageBoard = pageName
            //    tree.URLGroup = pageName + "?GroupId=" & tree.Group.Id
            //    tree.Language = currentLanguage
            //    treeDiv.Controls.Add(tree)
            //End If

            // ThreadList
            if (Request.QueryString["Forum"] == "ThreadList")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.Forum = MessageBoard.Forum.Get(int.Parse(Request.QueryString["ForumId"]));
                tree.URLMessageBoard = pageName;
                tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Forum.Category.Group.Id;
                tree.URLCategory = pageName + "?";
                tree.URLForum = pageName + "?";
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            //// EditThread
            //If Request.QueryString("Forum") = "EditThread" Then
            //    Dim tree As MessageBoardControl.Tree = New MessageBoardControl.Tree
            //    tree.ImagesFolder = "Images/Forum"
            //    tree.Thread = editThread.Thread
            //    tree.URLMessageBoard = pageName
            //    tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" & tree.Thread.Forum.Category.Group.Id
            //    tree.URLCategory = pageName + "?"
            //    tree.URLForum = pageName + "?Forum=ThreadList&ForumId=" & tree.Thread.Forum.Id
            //    tree.Language = currentLanguage
            //    treeDiv.Controls.Add(tree)
            //End If

            //// DeleteThread
            //If Request.QueryString("Forum") = "DeleteThread" Then
            //    Dim tree As MessageBoardControl.Tree = New MessageBoardControl.Tree
            //    tree.ImagesFolder = "Images/Forum"
            //    tree.Thread = thread
            //    tree.URLMessageBoard = pageName
            //    tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" & tree.Thread.Forum.Category.Group.Id
            //    tree.URLCategory = pageName + "?"
            //    tree.URLForum = pageName + "?Forum=ThreadList&ForumId=" & tree.Thread.Forum.Id
            //    tree.Language = currentLanguage
            //    treeDiv.Controls.Add(tree)
            //End If

            //// LockThread
            //If Request.QueryString("Forum") = "LockThread" Then
            //    Dim tree As MessageBoardControl.Tree = New MessageBoardControl.Tree
            //    tree.ImagesFolder = "Images/Forum"
            //    tree.Thread = lockThread.Thread
            //    tree.URLMessageBoard = pageName
            //    tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" & tree.Thread.Forum.Category.Group.Id
            //    tree.URLCategory = pageName + "?"
            //    tree.URLForum = pageName + "?Forum=ThreadList&ForumId=" & tree.Thread.Forum.Id
            //    tree.Language = currentLanguage
            //    treeDiv.Controls.Add(tree)
            //End If

            // PostList
            if (Request.QueryString["Forum"] == "PostList")
            {
                MessageBoard.Thread thread = MessageBoard.Thread.Get(int.Parse(Request.QueryString["ThreadId"]));
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.Thread = thread;
                tree.URLMessageBoard = pageName;
                tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Thread.Forum.Category.Group.Id;
                tree.URLCategory = pageName + "?";
                tree.URLForum = pageName + "?Forum=ThreadList&ForumId=" + tree.Thread.Forum.Id;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            if (Request.QueryString["Forum"] == "EditPost")
            {
                MessageBoard.Post post = MessageBoard.Post.Get(int.Parse(Request.QueryString["PostId"]));
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                tree.ImagesFolder = "/Images/Forum";
                tree.Thread = post.Thread;
                tree.URLMessageBoard = pageName;
                tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Thread.Forum.Category.Group.Id;
                tree.URLCategory = pageName + "?";
                tree.URLForum = pageName + "?Forum=ThreadList&ForumId=" + tree.Thread.Forum.Id;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }

            //// DeletePost
            //If Request.QueryString("Forum") = "DeletePost" Then
            //    Dim tree As MessageBoardControl.Tree = New MessageBoardControl.Tree
            //    tree.ImagesFolder = "Images/Forum"
            //    tree.Thread = post.Thread
            //    tree.URLMessageBoard = pageName
            //    tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" & tree.Thread.Forum.Category.Group.Id
            //    tree.URLCategory = pageName + "?"
            //    tree.URLForum = pageName + "?Forum=ThreadList&ForumId=" & tree.Thread.Forum.Id
            //    tree.Language = currentLanguage
            //    treeDiv.Controls.Add(tree)
            //End If

            if (Request.QueryString["Forum"] == "ManageSecurity")
            {
                MessageBoardControl.Tree tree = new MessageBoardControl.Tree();
                if (!string.IsNullOrEmpty(Request.QueryString["GroupId"]))
                {
                    tree.Group = MessageBoard.Group.Get(int.Parse(Request.QueryString["GroupId"]));
                }
                else if (!string.IsNullOrEmpty(Request.QueryString["CategoryId"]))
                {
                    tree.Category = MessageBoard.Category.Get(int.Parse(Request.QueryString["CategoryId"]));
                    tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Category.Group.Id;
                }
                else if (!string.IsNullOrEmpty(Request.QueryString["ForumId"]))
                {
                    tree.Forum = MessageBoard.Forum.Get(int.Parse(Request.QueryString["ForumId"]));
                    tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Forum.Category.Group.Id;
                }
                else if (!string.IsNullOrEmpty(Request.QueryString["ThreadId"]))
                {
                    tree.Thread = MessageBoard.Thread.Get(int.Parse(Request.QueryString["ThreadId"].ToString()));
                    tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Thread.Forum.Category.Group.Id;
                    tree.URLCategory = pageName + "?";
                    tree.URLForum = pageName + "?Forum=ThreadList&ForumId=" + tree.Thread.Forum.Id;
                }
                else if (!string.IsNullOrEmpty(Request.QueryString["PostId"]))
                {
                    MessageBoard.Post post = MessageBoard.Post.Get(int.Parse(Request.QueryString["PostId"].ToString()));
                    tree.Thread = post.Thread;
                    tree.URLGroup = pageName + "?Forum=CategoryList&GroupId=" + tree.Thread.Forum.Category.Group.Id;
                    tree.URLCategory = pageName + "?";
                    tree.URLForum = pageName + "?Forum=ThreadList&ForumId=" + tree.Thread.Forum.Id;
                }

                tree.ImagesFolder = "/Images/Forum";
                tree.URLMessageBoard = pageName;
                tree.Language = currentLanguage;
                treeDiv.Controls.Add(tree);
            }
        }
    }
}
